from bs4 import BeautifulSoup
path = './1_2_homework_required/index.html'
info = []
with open(path,'r') as f:
    Soup = BeautifulSoup(f,'lxml')
    # img_banner = Soup.select('body > div > div > div.col-md-9 > div > div.col-md-12 > div > div > div.item > img')
    img = Soup.select('body > div > div > div.col-md-9 > div > div > div.thumbnail > img')
    title = Soup.select('body > div > div > div.col-md-9 > div > div > div.thumbnail > div.caption > h4 > a')
    price = Soup.select('body > div > div > div.col-md-9 > div > div > div.thumbnail > div.caption > h4.pull-right')
    desc = Soup.select('body > div > div > div.col-md-9 > div > div > div.thumbnail > div.caption > p')
    reviews = Soup.select('body > div > div > div.col-md-9 > div > div > div.thumbnail > div.ratings > p.pull-right')
    estimate = Soup.select('body > div > div > div.col-md-9 > div > div > div.thumbnail > div.ratings > p:nth-of-type(2)')
    # print(img_banner,img,title,price,desc,reviews,estimate,sep='\n')

for img,title,price,desc,reviews,estimate in zip(img,title,price,desc,reviews,estimate):
    data = {
        # 'img_banner' : img_banner.get('src'),
        'img' : img.get('src'),
        'title' : title.get_text(),
        'price' : price.get_text(),
        'desc' : desc.get_text(),
        'reviews' : reviews.get_text(),
        'estimate' : len(estimate.find_all('span',class_="glyphicon-star"))
    }
    info.append(data)
print(info,sep='\n')
for i in info:
    print(i['estimate'],sep='\t')

